-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Differential Testing for Merkle.rs #524
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for contracts-stylus canceled.
|
@0xNeshi i have added one differential test . Please let me know for any changes required ! |
@@ -661,4 +663,36 @@ mod tests { | |||
); | |||
assert!(verification.is_err()); | |||
} | |||
|
|||
#[test] | |||
fn test_differential_verifies_valid_proof() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this a differential fuzz test. That way we can test outputs for a huge number of inputs, and not just hardcoded ones.
Ideally we would configure the generated input to fit the expected data for a merkle proof validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xNeshi i'll make the changes asap
assert_eq!( | ||
rebuilt_root, root, | ||
"Rebuilt root does not match expected root" | ||
); | ||
assert!(verification, "Verifier::verify returned false"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the result of Verifier::verify
should be true
only if rebuilt_root == root
(i.e. the merkle proof is valid, so process_proof
generated the correct root), then the assertion should be:
assert_eq!(verification == (rebuilt_root == root), "Mismatch found");
@@ -14,6 +14,8 @@ num-traits.workspace = true | |||
zeroize.workspace = true | |||
educe.workspace = true | |||
hex-literal.workspace = true | |||
ethers-core = "1.0.2" | |||
merkle-tree-rs = "0.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have used merkle-tree-rs instead of rs-merkle because rs-merkle only supports sha256 and sha384, to use it for testing i have to implement shabuilder just like keccakbuilder.
I'd prefer we use rs-merkle
, as it's more popular and thus more reliable as a litmus test.
We should be able to easily configure it to use keccak256.
Resolves #502
PR Checklist